/*
 * strategy.cpp
 *
 *  Created on: Apr 24, 2014
 *      Author: zby
 */

#include <iostream>
#include <math.h>
#include "strategy.hpp"

using namespace strate;

const int Figure::len=5;

//1. --------------------------square class:
Square * Square::psquare = NULL;

Square::~Square(){
    if(Square::psquare!=NULL)
        delete Square::psquare;
}

Square* Square::getSingleton(){
    if(Square::psquare==NULL)  Square::psquare= new Square();
    return Square::psquare;
}

int Square::field(){
    std::cout<<"Square: ";
    return (Figure::len * Figure::len);
}

//2. --------------------------triangle class:
Triangle * Triangle::ptriangle = NULL;

Triangle::~Triangle(){
    if(Triangle::ptriangle!=NULL)
        delete Triangle::ptriangle;
}

Triangle* Triangle::getSingleton(){
    if(Triangle::ptriangle==NULL)  Triangle::ptriangle= new Triangle();
    return Triangle::ptriangle;
}

int Triangle::field(){
    std::cout<<"Triangle: ";
    return (Figure::len * sqrt(3)/2);
}

//3. --------------------------Round class:
Round * Round::pround = NULL;

Round::~Round(){
    if(Round::pround!=NULL)
        delete Round::pround;
}

Round* Round::getSingleton(){
    if(Round::pround==NULL)  Round::pround= new Round();
    return Round::pround;
}

int Round::field(){
    std::cout<<"Round: ";
    return (0.25*Figure::len * Figure::len * 3.14);
}

//4. --------------------------Strategy-Design-Pattern class:
Strategy::~Strategy() {
    if(this->pfig!=NULL)
        delete this->pfig;
}

void Strategy::set_figure(Figure * pfigr){
    this->pfig=pfigr;
}

int Strategy::show_field(){
    return this->pfig->field();

 }
